package com.tencent.wuyanzu.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.tencent.wuyanzu.dao.BaseDao;
import com.tencent.wuyanzu.dao.TagDao;
import com.tencent.wuyanzu.model.Food;
import com.tencent.wuyanzu.model.Tag;


@Repository
public class TagDaoImpl implements TagDao{

	@Autowired
	private BaseDao baseDao;
	
	@Override
	public List<Tag> getAllTags() {
		return baseDao.getAllValues(Tag.class);
	}

	@Override
	public List<Food> getFood(int TagID) {
		Session session = baseDao.getSession();
		Criteria criteria = session.createCriteria(Tag.class);
		criteria.add(Restrictions.eq("tadID", TagID));  
		List<Tag> list = criteria.list();
		if(list.isEmpty()){
			return new ArrayList<Food>();
		}else{
			return new ArrayList<Food>(list.get(0).getFood());
		}
		
	}

}
